import config from '../../../src/config'

function getfunc () {
  $.get(config.serverURI+'/demo/materials/function', '', function (res) {
    // console.log( res.aggregations[2].buckets );
    var data = [];

    res.aggregations[2].buckets.forEach(function (item, key) {
        data.push({'name': item.key, 'value': item.doc_count})
    });

    // var maskImage = new Image();
    //
    // maskImage.src = '/static/img/mask.png';

    var option = {
        title: {
            text: "布料功能",
            top: "top",
            left: "center"
        },
        tooltip: {
        },
        toolbox: {
            show: true,
            feature: {
                dataView: {
                    show: true,
                    readOnly: true
                },
                restore: {
                    show: true
                },
                saveAsImage: {
                    show: true
                }
            }
        },
        series: [{
          type: 'wordCloud',

          sizeRange: [25, 75],
          //rotationRange: [-90, 90],
          rotationRange: [0, 0],
          rotationStep: 45,
          gridSize: 2,
          shape: 'pentagon',

          // Global text style
          textStyle: {
              normal: {
                  fontFamily: 'sans-serif',
                  fontWeight: 'bold',
                  // Color can be a callback function or a color string
                  color: function () {
                      // Random color
                      return 'rgb(' + [
                          Math.round(Math.random() * 160),
                          Math.round(Math.random() * 160),
                          Math.round(Math.random() * 160)
                      ].join(',') + ')';
                  },
                  //fontSize: 30,
                  verticalAlign: 'center',
                  //align: 'center'
              },
              emphasis: {
                  shadowBlur: 10,
                  shadowColor: '#f00'
              }
          },

          animationType: 'scale',
          animationEasing: 'elasticOut',
          animationDelay: function (idx) {
              return Math.random() * 200;
          },

          // Data is an array. Each array item must have name and value property.
          data: data.sort(function (a, b) {
              return b.value  - a.value;
          })
      }]
    }
    var chart = echarts.init(document.getElementById('function'))

    //maskImage.onload = function () {
    //    option.series[0].maskImage
        chart.setOption(option);
    //}

  },'json');
}

export { //很关键
  getfunc
}
